package com.nk.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nk.system.beans.ProgramBean;
import com.nk.system.beans.ScoreStatBean;
import com.nk.system.common.search.Search;
import com.nk.system.dao.ScoreStatDao;
import com.nk.system.domain.ScoreStat;
import com.nk.system.service.PredictService;

@Service("predictService")
public class PredictServiceImpl extends GenericServiceImpl<ScoreStat, Integer, ScoreStatDao>  implements PredictService{
	
	private Logger log = Logger.getLogger(AuthenticationServiceImpl.class);
	
	@Autowired
	public PredictServiceImpl(ScoreStatDao scoreStatDao) {
		super(scoreStatDao);
	}

	@Override
	public List<ScoreStatBean> getPredictResult(ProgramBean majorID) {
		// TODO Auto-generated method stub
		
		List<ScoreStatBean> scoreStatList = new ArrayList<ScoreStatBean>();
		
		try {
			Search search = new Search(ScoreStat.class);
			search.addFilterEqual("pid", majorID.getId());
			search.addSortAsc("year");
			
			List<ScoreStat> scoreList = dao.search(search);
		
			for(ScoreStat stat:scoreList) {
				ScoreStatBean scoreStatBean = new ScoreStatBean();
				scoreStatBean.setId(stat.getId());
				scoreStatBean.setPid(stat.getPid());
				scoreStatBean.setYear(stat.getYear());
				scoreStatBean.setPeople(stat.getPeople());
				scoreStatBean.setMax(stat.getMax());
				scoreStatBean.setMin(stat.getMin());
				scoreStatBean.setAvg(stat.getAvg());
				scoreStatBean.setSd(stat.getSd());
				
				scoreStatList.add(scoreStatBean);
			}
			
		}catch(Exception e) {
			log.error(e,e);
		}
		
		return scoreStatList;
	}

}
